<?php
namespace Common\Model;
use Common\Model\CommonModel;
// +----------------------------------------------------------------------
// | Date:2017年7月26日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class EmployeeUserModel extends CommonModel{
    protected $approver_cache_key = 'approver_sn_all';
    
    /**
     * 生成审核人名单，并且写入缓存
     * 
     * date:2017年7月26日
     * author: EK_熊
     */
    function create_approver_list(){
        $userlist = $this->get_approver_list_db();
        
        if (!$userlist) return false; 
        
        F($this->approver_cache_key,$userlist);//写入文件缓存
        return $userlist;
    }
    
    /**
     * 获取审核人名单，优先从缓存获取
     * @return mixed|void|boolean|NULL
     * date:2017年7月26日
     * author: EK_熊
     */
    function get_approver_list(){
        $approverlist = F($this->approver_cache_key);
        
        if ($approverlist) return $approverlist;
        $approverlist = $this->get_approver_list_db();
        $this->create_approver_list();
    }
    
    function get_approver_list_db(){
        $approverid_map['approver_id'] = ['gt',0];
        $approverid_map['status'] = 1;
        $sub_id = $userlist = $this->where($approverid_map)->distinct('approver_id')->getField('approver_id',true);
        $approver_sn_map['ep_id'] = ['in',$sub_id];
        $approver_sn_map['sn'] = ['neq',''];
        $approver_sn_map['status'] = 1;
        $userlist = $this->where($approver_sn_map)->getField('sn',true);
        return $userlist;
    }
    
}